﻿using Microsoft.AspNet.SignalR;
using Microsoft.Owin;
using Microsoft.Owin.Cors;
using Owin;

[assembly: OwinStartup(typeof(Practices.SignalR.Startup))]
namespace Practices.SignalR {
    public class Startup {
        public void Configuration(IAppBuilder app) {
            // Any connection or hub wire up and configuration should go here
            // app.MapSignalR();

            // The following example shows how to specify the SignalR connection URL and these options 
            // in a call to the MapSignalR method.  
            // To specify a custom URL, replace "/signalr" in the example with the URL that you want to use.
            //var configuration = new HubConfiguration() {
            //    EnableDetailedErrors = true,
            //    EnableJavaScriptProxies = false,
            //};
            //app.MapSignalR("/signalr", configuration);

            // Branch the pipeline here for requests that start with "/signalr"
            app.Map("/signalr", map => {
                // Setup the CORS middleware to run before SignalR.
                // By default this will allow all origins. 
                // You can configure the set of origins and/or http verbs 
                // by providing a cors options with a different policy.
                map.UseCors(CorsOptions.AllowAll);
                var configuration = new HubConfiguration {
                    // You can enable JSONP by uncommenting line below.
                    // JSONP requests are insecure but some older browsers (and some
                    // versions of IE) require JSONP to work cross domain
                    EnableJSONP = true,
                    EnableDetailedErrors = true
                };
                // Run the SignalR pipeline. We're not using MapSignalR
                // since this branch already runs under the "/signalr" path.
                map.RunSignalR(configuration);
            });
        }
    }
}
